<?php

/*
 *  Copyright (C) 2012 etpass
 * 
 *  author:chl <chenhl, chenhl@etpass.com>
 *  date:2013-3-29
 *  encoding:UTF-8
 *  filename:simpleXML.class.php
 *  link:http://www.etpass.com
 */

class simpleXML{
    
    
        public static function xml2array($xml = '') {

        $dom = new DOMDocument();
        $dom->loadXML($xml);
        $dom_root = $dom->documentElement;
        $arr = array();
        foreach ($dom_root->childNodes as $items) {
            if ($items->hasChildNodes()) {
                $array = array();
                foreach ($items->childNodes as $item) {
                    if ($item->tagName) {
                        $array[$item->tagName] = $item->nodeValue;
                    }
                }
                $arr[] = $array;
            }
        }
        if (!empty($arr)) {
            return $arr;
        } else {
            return '';
        }
    }
    
}

?>
